package com.link2room.rodimus.nmsrunner;

import com.aliyun.mns.model.Message;
import com.link2room.common.mns.Worker;
import com.link2room.common.util.ExceptionUtil;
import com.link2room.common.util.JacksonUtil;
import com.link2room.common.util.LogUtil;
import com.link2room.rodimus.dto.param.base.PointBaseParamDto;
import com.link2room.rodimus.facade.IPointFacadeService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Created by sss on 2016/9/21.
 */
@Component("pointRunner")
public class PointRunnerImpl implements Worker {
    @Resource
    private IPointFacadeService pointFacadeService;

    @Override
    public boolean exec(Message message) throws Exception {
        try{
            PointBaseParamDto pointBaseParamDto = JacksonUtil.jsonToBean(message.getMessageBody(), PointBaseParamDto.class);
            if(message.getDequeueCount()==1){
                pointFacadeService.reservationPoint(pointBaseParamDto);
            }
            return true;
        }catch (Exception e){
            String errorDetail= ExceptionUtil.getExceptionDetail(e);
            LogUtil.logger.error(errorDetail);
            return false;
        }
    }
}
